package com.imagination.applet.controller.api;


import com.imagination.applet.controller.api.response.HealthCheckResponse;
import com.imagination.applet.infrastructure.common.RestResponse;
import com.imagination.applet.infrastructure.logging.Log;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;

@RestController
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
//@Tag(name = "健康检查")
public class HealthCheckController {

    @Value("${payment.wechat.bind-parent-path}")
    public String bindParentPath;
    @Log
    @GetMapping(value = "/hello")
    public RestResponse<HealthCheckResponse> healthCheck() {
        return RestResponse.ok(HealthCheckResponse.of("I am ok!!!"));
    }

    @GetMapping("/key/YdBjMczYHG.txt")
    public ResponseEntity<byte[]> getStaticFile() throws IOException {
        // 读取静态文件
        byte[] data = Files.readAllBytes(new File(bindParentPath).toPath());
        // 返回静态文件内容
        return ResponseEntity.ok()
                .contentType(MediaType.TEXT_HTML)
                .body(data);
    }


}
